package com.zhan.drugStore.controller;


import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;
import com.zhan.drugStore.bean.entity.Bill;
import com.zhan.drugStore.bean.form.BillSearch;
import com.zhan.drugStore.bean.vo.BillVO;
import com.zhan.drugStore.util.BeanUtils;
import com.zhan.drugStore.util.ResponseBase;
import com.zhan.drugStore.util.ResponseBean;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zy
 * @since 2024-06-08
 */
@RestController
@RequestMapping("/bill")
public class BillController extends SuperController {

    @PostMapping("/addOrUpdate")
    @ApiOperation("/新增或修改")
    public ResponseBase addOrUpdate(@RequestBody Bill bill) {
        super.billService.addOrUpdate(bill);
        return super.resultSuccess();
    }

    @PostMapping("/list")
    @ApiOperation("/列表")
    public ResponseBean<PageInfo<BillVO>> billList(@RequestBody BillSearch form) {
        if(form.getPage() != null && form.getLimit() != null) {
            PageMethod.startPage(form.getPage(), form.getLimit());
        }
        return super.resultSuccess(new PageInfo<>(super.billService.billList(form)));
    }

    @GetMapping("/getBillById")
    @ApiOperation("/列表")
    public ResponseBean<BillVO> gitBillById(@RequestParam Long id) {
        Bill billVO = super.billService.getById(id);
        return super.resultSuccess(BeanUtils.objToObj(billVO, BillVO.class));
    }

    @GetMapping("/delete")
    @ApiOperation("/删除")
    public ResponseBase delete(@RequestParam("id") Long id) {
        super.billService.removeById(id);
        return super.resultSuccess();
    }


}

